<?php
/**
 * +----------------------------------------------------------------------
 * | Author: 罗极
 * +----------------------------------------------------------------------
 * | Description: HtmlView.php
 * +----------------------------------------------------------------------
 * | User: Administrator Date: 8/21/ 0021 Time: 15:42
 * +----------------------------------------------------------------------
 */

namespace Framework\View;

use Framework\View\Abstracts\ViewAbstract;
use Framework\View\Exception\NotFoundException;

class HtmlView extends ViewAbstract
{

    public function __construct(array $assign)
    {
        $this->assignArr($assign);
    }

    public function assign(string $key, string $val)
    {
        $this->assign[$key] = $val;
    }

    public function assignArr(array $assign)
    {
        $this->assign = array_merge($this->assign, $assign);
    }

    public function show(string $path = '')
    {
        $this->viewPath = ViewConfig::getViewPath($path);
        unset($path);

        if(!file_exists($this->viewPath)) {
            throw new NotFoundException(sprintf(
                '没有找到视图文件: [%s]',
                $this->viewPath
            ));
        }

        extract($this->assign);

        include $this->viewPath;

    }


}